#include "Solver.h"

Solver fluid;

int width=60, height=60;


void display()
{
	fluid.SolverUpdate();


	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0.0, width*2, 0.0, height*2);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glViewport(0, 0, width*2, height*2);

	glPolygonMode(GL_FRONT,GL_FILL);

	glEnable(GL_TEXTURE_RECTANGLE_ARB);
	glBindTexture(GL_TEXTURE_RECTANGLE_ARB,fluid.density->bufferID);

	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 0.0); 
	glVertex2f(0.0, 0.0);
	glTexCoord2f(width, 0.0); 
	glVertex2f(width*2, 0.0);
	glTexCoord2f(width, height); 
	glVertex2f(width*2, height*2);
	glTexCoord2f(0.0, height); 
	glVertex2f(0.0, height*2);
	glEnd();

	glDisable(GL_TEXTURE_RECTANGLE_ARB);

	//glDrawPixels(width,height,GL_RGB,GL_FLOAT,result);

	glutSwapBuffers();

	glutPostRedisplay();


}

void main(int argc, char *argv[])
{
	glutInit ( &argc, argv );
	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
	glutInitWindowSize(width*2, height*2);
	glutCreateWindow("GPGPU");
	glutDisplayFunc(display);

	fluid.SolverInit(width,height,GL_RGB32F_ARB,GL_RGB,GL_FLOAT,GL_TEXTURE_RECTANGLE_ARB);

	glutMainLoop();
}